package edu.neusoft.android.yuejian14.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import edu.neusoft.android.yuejian14.Listener.RetrofitListener;
import edu.neusoft.android.yuejian14.R;
import edu.neusoft.android.yuejian14.javabean.Pic;
import edu.neusoft.android.yuejian14.model.PicModel;

import static edu.neusoft.android.yuejian14.Const_Pic.BASE_URL;

public class PicDetailActivity extends BaseActivity implements View.OnClickListener,RetrofitListener {
    private TextView u_name,u_time,u_topic,u_content;
    private static ImageView u_photo,pic0,pic1,pic2;
    private ImageButton back;
    private int cardid;



    @Override
    protected void initViews(){
        setLayout(R.layout.pic_detail);
        u_name= (TextView) findViewById(R.id.u_name);
        u_time= (TextView) findViewById(R.id.u_time);
        u_photo= (ImageView) findViewById(R.id.my_photo);
        pic0= (ImageView) findViewById(R.id.pic);
        pic1= (ImageView) findViewById(R.id.pic1);
        pic2= (ImageView) findViewById(R.id.pic2);
        u_topic=(TextView) findViewById(R.id.u_topic);
        u_content=(TextView) findViewById(R.id.u_content);
        back=(ImageButton) findViewById(R.id.btn_back);

    }

    @Override
    View initViews(View view) {

        return view;
    }

    @Override
    void initEvents() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    void initData() {
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        cardid=bundle.getInt("cardid");

        PicModel picModel = new PicModel();
        picModel.getCardById(String.valueOf(cardid),this);
    }

    @Override
    public void onSuccess(Object object, int flag) {
                   Pic pic= (Pic) object;
                    u_name.setText(pic.getUsername());
                    u_time.setText(pic.getCardtime());
                    u_topic.setText(pic.getTopic());
                    u_content.setText(pic.getCardcontent());

                     String u_photo = BASE_URL  + pic.getPhoto();
                    if (!"".equals(pic.getPhoto()))
                        Picasso.with(PicDetailActivity.this).load(u_photo).error(R.drawable.no_pic).into(PicDetailActivity.u_photo);
                    String pic0= BASE_URL  + pic.getCardpic();
                    if (!"".equals(pic.getCardpic()))
                        Picasso.with(PicDetailActivity.this).load(pic0).error(R.drawable.no_pic).into(PicDetailActivity.pic0);
                    String pic1= BASE_URL  + pic.getPhoto1();
                    if (!"".equals(pic.getPhoto1()))
                        Picasso.with(PicDetailActivity.this).load(pic1).error(R.drawable.no_pic).into(PicDetailActivity.pic1);
                    String pic2= BASE_URL  + pic.getPhoto2();
                    if (!"".equals(pic.getPhoto2()))
                        Picasso.with(PicDetailActivity.this).load(pic2).error(R.drawable.no_pic).into(PicDetailActivity.pic2);

    }

    @Override
    public void onFail() {

    }

    @Override
    public void onClick(View view) {

    }
}